package net.fdukedom.chart.constraints;

import net.fdukedom.chart.Function2D;

/**
 * 
 * Constraint of type <code>function</code> >= 0 
 * 
 * @author Fedor Tsarev
 *
 */
public class NonNegativeConstraint extends Constraint {

	public NonNegativeConstraint(Function2D function) {
		super(function);
	}

	@Override
	public boolean[][] getContainsMap(int width, int height, double minX, double minY, double maxX, double maxY) {
		boolean[][] res = new boolean[width][height];
		double dx = (maxX - minX) / width;
		double dy = (maxY - minY) / height;
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				double val = function.value(minX + dx * i, minY + dy * j);
				res[i][j] = val >= 0 && !Double.isInfinite(val) && !Double.isNaN(val);
			}
		}
		return res;
	}

}
